<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>函数只执行一次</title>
</head>
<body>
<script>

    function execute_once(fn) {
        let times = true

        return function () {
            if (times) {
                times = false
                fn.apply(this.arguments)
            }
        }
    }

    // console.log(times);

    function f() {
        console.log('output from f()');
    }

    let once = execute_once(f);

    once()
    once()
    once()


</script>
</body>
</html>